<template>
  <div>
    <el-container>
      <el-header>
        <div>
          <img src="../assets/images/小黄鸡.png" class="logo-img">
          <span>多媒体接单后台管理系统</span>
        </div>
        <img :src="manager.managerImg" style="width: 55px;height: 55px;border-radius: 100%;margin-left: 900px;cursor: pointer">
        <el-button type="info" @click="logout">退出</el-button>
      </el-header>
      <el-container class="home-container">
        <el-aside :width="isCollapse ? '60px' : '200px'">
          <div class="toggle-button" @click="toggleCollapse">|||</div>
          <el-menu
            default-active="2"
            @open="handleOpen"
            @close="handleClose"
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409EFF"
            unique-opened
            :collapse="isCollapse"
            :collapse-transition="false"
            router
            :default-active="activePath">
            <el-submenu :index="menu.menuId + ''" v-for="menu in menus" :key="menu.menuId">
              <template slot="title">
                <i :class="iconsObj[menu.menuId]"></i>
                <span>{{menu.menuName}}</span>
              </template>
              <el-menu-item :index="'/' + menuList.path" v-if="menu.menusList.length != 0"
                            v-for="menuList in menu.menusList" :key="menuList.menuId"
                            @click="saveMenuState('/' + menuList.path)">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{menuList.menuName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>

        </el-aside>
        <!--        <div style="width: 100%;margin-left: 10px;">-->
        <!--          <h3 style="font-size:40px;">欢迎进入多媒体接单平台后台管理系统</h3>-->
        <!--        </div>-->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>

    </el-container>

  </div>
</template>

<script>
    import {logout} from "../assets/api/loginApi";
    import {getMenusList} from "../assets/api/menusApi";
    import {getManagerById} from "../assets/api/managerApi";


    export default {
        name: 'home',
        data() {
            return {
                menus: [],
                iconsObj: {
                    1: 'iconfont icon-gerenzhongxin',
                    2: 'iconfont icon-celveguanli',
                    3: 'iconfont icon-xitongguanli',
                    4: 'iconfont icon-gongdanguanli',
                    8: 'iconfont icon-quanxianguanli',
                    10: 'iconfont icon-taishifenxi'
                },
                activePath: '',
                isCollapse: false,
                manager: {}
            }
        },
        methods: {
            logout() {
                logout().then((res) => {
                    this.$router.replace('/');
                });
            },
            saveMenuState(activePath) {
                window.sessionStorage.setItem('activePath', activePath);
                this.activePath = activePath;
            },
            getMenuList() {
                getMenusList().then((res) => {
                    this.menus = res.data;
                })
            },
            toggleCollapse() {
                this.isCollapse = !this.isCollapse;
            },
            handleOpen(key, keyPath) {
                console.log(key, keyPath);
            },
            handleClose(key, keyPath) {
                console.log(key, keyPath);
            },
            getManager() {
                let data = {};
                data.managerId = localStorage.managerId;
                getManagerById(data).then(res => {
                    this.manager = res.data;
                })
            },
        },
        created() {
            this.getManager();
            this.getMenuList();
            this.activePath = window.sessionStorage.getItem('activePath')
        },

    }
</script>

<style lang="less" scoped>
  .home-container {
    height: 580px;
  }

  /deep/ .el-header {
    background-color: #373D41;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    color: #fff;
    font-size: 20px;

    > div {
      display: flex;
      align-items: center;

      span {
        margin-left: 15px;
      }
    }
  }

  .logo-img {
    border-radius: 50%;
    width: 20%;
  }

  /deep/ .el-aside {
    background-color: #333744;

    .el-menu {
      border-right: none;
    }
  }

  .toggle-button {
    background-color: #4A5064;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }

  /deep/ .el-main {
    background-color: #EAEDF1;
  }

  .iconfont {
    margin-right: 10px;
  }
</style>
